package org.hxyjs.service.impl;


import org.hxyjs.dao.FestivalDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Festival;
import org.hxyjs.entity.Festival;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.FestivalService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("FestivalService")
public class FestivalServiceImpl implements FestivalService {
    @Resource
    FestivalDao festivalDao;
    @Override
    public DTO<Festival> getAllFestivals()  throws Exception{
        List<Festival> festivals = festivalDao.getAllFestivals();
        MessageEnum messageEnum  = Optional.ofNullable(festivals).isPresent()?MessageEnum.GETFESTIVALSUCCESS: MessageEnum.GETFESTIVALFAIL;
        return new DTO<Festival>(messageEnum.getCode(),messageEnum.getMessage(),festivals);
    }

    @Override
    public DTO<Festival> deleteFestivalByFno(String fno)  throws Exception{
        Integer result = festivalDao.deleteFestivalByFno(fno);
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEFESTIVALSUCCESS:MessageEnum.DELETEFESTIVALFAIL;
        return new DTO<Festival>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Festival> updateFestivalByFno(Festival festival)  throws Exception{
        Integer result = festivalDao.updateFestivalByFno(festival);
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEFESTIVALSUCCESS:MessageEnum.UPDATEFESTIVALFAIL;
        return new DTO<Festival>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Festival> addFestival(Festival festival) throws Exception {
        Integer result = festivalDao.addFestival(festival);
        MessageEnum messageEnum  = result> 0?MessageEnum.ADDFESTIVALSUCCESS:MessageEnum.ADDFESTIVALFAIL;
        return new DTO<Festival>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Festival> getFestivalByPage(PageInfo pageInfo ) throws Exception {
        List<Festival> festivals = festivalDao.getFestivalByPage(pageInfo);
        MessageEnum messageEnum  = Optional.ofNullable(festivals).isPresent()?MessageEnum.GETFESTIVALSUCCESS: MessageEnum.GETFESTIVALFAIL;
        return new DTO<Festival>(messageEnum.getCode(),messageEnum.getMessage(),festivals,pageInfo);
    }
}
